package com.lzm.ydpt.module.mall.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.byt.framlib.base.BaseFragment;
import com.byt.framlib.commonutils.image.ImageLoaderUtils;
import com.byt.framlib.commonwidget.onclicktwo.AntiShake;
import com.byt.framlib.commonwidget.refresh.RefreshHeaderView;
import com.lzm.ydpt.R;
import com.lzm.ydpt.entity.UserInfo;
import com.lzm.ydpt.module.mall.activity.ChangeProductStateActivity;
import com.lzm.ydpt.module.mall.activity.DiscountActionActivity;
import com.lzm.ydpt.module.mall.activity.MallFollowActivity;
import com.lzm.ydpt.module.mall.activity.MallOrderListActivity;
import com.lzm.ydpt.module.mall.activity.MessageCenterActivity;
import com.lzm.ydpt.module.mall.activity.MyVCurrencyActivity;
import com.lzm.ydpt.module.mall.activity.OrderAddressListActivity;
import com.lzm.ydpt.module.mall.activity.ProductHistoryActivity;
import com.lzm.ydpt.module.mall.activity.ProductLoveActivity;
import com.lzm.ydpt.mvp.contract.MallMineContract;
import com.lzm.ydpt.mvp.presenterimpl.MallMinePresenterImpl;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 商城个人中心
 */
public class MallMineFragment extends BaseFragment<MallMinePresenterImpl> implements MallMineContract.View {
    private static MallMineFragment sFragment;
    @BindView(R.id.myinfo_refreshLayout)
    SmartRefreshLayout myinfo_refreshLayout;
    @BindView(R.id.img_touxiang)
    ImageView img_touxiang;
    @BindView(R.id.tv_user_name)
    TextView tv_user_name;
    @BindView(R.id.tv_mall_follow_num)
    TextView tv_mall_follow_num;
    @BindView(R.id.tv_love_product_num)
    TextView tv_love_product_num;
    @BindView(R.id.tv_history_product_num)
    TextView tv_history_product_num;
    @BindView(R.id.tv_coupons_num)
    TextView tv_coupons_num;
    private UserInfo tempUserInfo;

    public static MallMineFragment newsInstance() {
        sFragment = new MallMineFragment();
        return sFragment;
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_mall_mine;
    }

    @Override
    public MallMinePresenterImpl initPresenter() {
        return new MallMinePresenterImpl(this);
    }

    @Override
    protected void initView() {
        initRefresh();
    }

    private void initRefresh() {
        setRefreshLayout(myinfo_refreshLayout);
        myinfo_refreshLayout.setEnableLoadMore(false);
        myinfo_refreshLayout.setEnableRefresh(true);
        myinfo_refreshLayout.setRefreshHeader(new RefreshHeaderView(context).getHeaderStyleStaffMain());
        myinfo_refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

            }
        });
    }

    @OnClick({R.id.img_touxiang, R.id.tv_user_name, R.id.img_jump_order_list, R.id.tv_my_order_data_all,
            R.id.ll_order_pay_jump, R.id.ll_order_revice_product_jump, R.id.ll_order_complete_jump,
            R.id.ll_order_change_jump, R.id.ll_my_follow_shop, R.id.ll_my_love_product, R.id.ll_my_history,
            R.id.ll_my_coupons, R.id.rl_revice_address, R.id.rl_v_currency_data, R.id.rl_msg_center,
            R.id.rl_my_customer_service})
    public void onClick(View view) {
        if (AntiShake.check(view.getId())) {
            return;
        }
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.img_touxiang:
            case R.id.tv_user_name:
                showShortToast("个人信息");
                break;
            case R.id.img_jump_order_list:
            case R.id.tv_my_order_data_all:
                openActivity(MallOrderListActivity.class);
                break;
            case R.id.ll_order_pay_jump:
                bundle.putInt(MallOrderListActivity.INP_ORDER_POSITION, 1);
                openActivity(MallOrderListActivity.class, bundle);
                break;
            case R.id.ll_order_revice_product_jump:
                bundle.putInt(MallOrderListActivity.INP_ORDER_POSITION, 2);
                openActivity(MallOrderListActivity.class, bundle);
                break;
            case R.id.ll_order_complete_jump:
                bundle.putInt(MallOrderListActivity.INP_ORDER_POSITION, 3);
                openActivity(MallOrderListActivity.class, bundle);
                break;
            case R.id.ll_order_change_jump:
                openActivity(ChangeProductStateActivity.class);
                break;
            case R.id.ll_my_follow_shop:
                openActivity(MallFollowActivity.class);
                break;
            case R.id.ll_my_love_product:
                openActivity(ProductLoveActivity.class);
                break;
            case R.id.ll_my_history:
                openActivity(ProductHistoryActivity.class);
                break;
            case R.id.ll_my_coupons:
                openActivity(DiscountActionActivity.class);
                break;
            case R.id.rl_revice_address:
                openActivity(OrderAddressListActivity.class);
                break;
            case R.id.rl_v_currency_data:
                openActivity(MyVCurrencyActivity.class);
                break;
            case R.id.rl_msg_center:
                openActivity(MessageCenterActivity.class);
                break;
            case R.id.rl_my_customer_service:
                showShortToast("客服");
//                openActivity(CustomerServiceActivity.class);
                break;
        }
    }

    @Override
    public void onDestroyView() {
        sFragment = null;
        super.onDestroyView();
    }

    @Override
    public void onUserInfoData(UserInfo userInfos) {
        if (userInfos != null) {
            this.tempUserInfo = userInfos;
            ImageLoaderUtils.displayCircle(img_touxiang, tempUserInfo.getIcon());
            tv_user_name.setText(tempUserInfo.getNickName());
            tv_mall_follow_num.setText(tempUserInfo.getNickName());
            tv_love_product_num.setText(tempUserInfo.getNickName());
            tv_coupons_num.setText(tempUserInfo.getNickName());
        }
    }

    @Override
    public void showMessage(String message, String method) {

    }

    @Override
    public void showErrorView(String msg) {

    }
}
